﻿#region UsingStatements

using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;

/*----------------------------------------------------------------
       // Copyright (C) 2008 安华顺通(北京)科技有限公司
       // 版权所有。 
       //
       // 文件名：BaseProperty.cs
       // 文件功能描述：所有属性的基类，提供所有结点属性的共同属性。
       //
       // 
       // 创建标识：杨波
       //
       // 修改标识：杨波20080903
       // 修改描述：增加MenuItem和Menu的反序列化器。
       //
       // 修改标识：杨波20080927
       // 修改描述：增加EDTInt64的反序列化器。
 * 
 *     // 修改标识：
       // 修改描述：
//----------------------------------------------------------------*/

#endregion

namespace RuleCode.ObjectTree
{
    public interface ISerializeToXML
    {
        void SerializeToXML();
    }
    //对于丁余良的所有控件，添加以下属性约束。
    public interface SerializablePropertyBase
    {
        string ID { get; set; }
        string Creator { get; set; }
        string ChangedBy { set; get; }
        DateTime CreationDate { set; get; }
        DateTime ChangedDate { set; get; }
        //string HelpContent { set; get; }
        string Name { set; get; }
        string Label { set; get; }
    }
    [DefaultProperty("ID"), DataContract(Namespace = "http://RuleCode.ObjectTree.Property")]
    public class BaseProperty : ISerializeToXML
    {
        //在所有属性前加[CategoryAttribute("Property")]，就不会出现杂项了
        private string id = "001";
        private string creator;
        private DateTime creationDate = DateTime.Now;
        private DateTime changedDate = DateTime.Now;

        public BaseProperty()
        {
            ID = id;
        }

        public BaseProperty(string _id)
        {
            ID = _id;
        }

        //在PropertyGrid中显示的顺序为类中按Attribute依次显示，父类在子类下
        [ReadOnly(true), Category("Property"), DataMember, Description("Internal number for element")]
        public string ID
        {
            set { id = value; }
            get { return id; }
        }

        [ReadOnly(true), Category("Property"), DataMember,
         Description("The name of the user who created this application object")]
        public string Creator
        {
            set { creator = value; }
            get { return creator; }
        }

        [ReadOnly(true), Description("The name of the user who last changed this application object"),
         DefaultValue(false),
         Category("Property"), DataMember]
        //DescriptionAttribute can be displayed on the bottom of PropertyGrid when the column is actived.
        public string ChangedBy { set; get; }

        [ReadOnly(true), Category("Property"), DataMember, Description("The date on which the object was created")]
        public DateTime CreationDate
        {
            set { creationDate = value; }
            get { return creationDate; }
        }

        [ReadOnly(true), Category("Property"), DataMember, Description("The date on which the object was last changed")]
        public DateTime ChangedDate
        {
            set { changedDate = value; }
            get { return changedDate; }

        }

        /*private string tableSelected;
        [TypeConverter(typeof(TableCollection)),CategoryAttribute("Property"), DataMember]
        public string TableCollection
        {
            get { return tableSelected; }
            set { tableSelected = value; }
        }
        */

        //[DataMember]
        //public string Description1 { get; set; }

        //[DataMember]
        //public string Description2 { get; set; }

        //[DataMember]
        //public string Description3 { set; get; }

        //[DataMember]
        //public string Description4 { set; get; }

        //[DataMember]
        //public string Description5 { set; get; }

        //[DataMember, Editor(typeof(LabelPropertyEditor), typeof(UITypeEditor))]
        //public string HelpContent { set; get; }

        public virtual void SerializeToXML()
        {
            /**FileStream writer = new FileStream(Path.GetDirectoryName(Application.ExecutablePath)+"\\ObjDatathis\\"+ID+".xml", FileMode.Create);
            DataContractSerializer ser =
                new DataContractSerializer(typeof(myRecord));
            ser.WriteObject(writer, this.myRecord1);
            writer.Close();**/
            //由于各个子属性项的差异，具体的序列化工作由各子属性完成。
            DataContractSerializer ser =
                new DataContractSerializer(GetType());
            FileStream writer = getFileWriter();
            ser.WriteObject(writer, this);
            writer.Close();           
            //MessageBox.Show("出现调用异常，子属性没有完成规定的任务");
        }

        protected FileStream getFileWriter()
        {

            string ObjDataFolder = Util.GetObjDataPath;
            DirectoryInfo dir = new DirectoryInfo(ObjDataFolder);
            if (!dir.Exists)
            {
                dir.Create();
            }
            FileStream writer = new FileStream(dir + "\\" + ID + ".xml", FileMode.Create, FileAccess.ReadWrite);
            return writer;
        }
    }

    public class SysDataContractSerializer
    {
        //使用单态模式，提供每一个具体Property反序列化器，然后返回反序列化后的对象
        private static DataContractSerializer EDTPropertySerializer;
        private static DataContractSerializer EDTStringPropertySerializer;
        private static DataContractSerializer EDTIntPropertySerializer;
        private static DataContractSerializer EDTRealPropertySerializer;
        private static DataContractSerializer EDTDatePropertySerializer;
        private static DataContractSerializer EDTTimePropertySerializer;
        private static DataContractSerializer EDTEnumPropertySerializer;
        private static DataContractSerializer EDTContainerPropertySerializer;
        private static DataContractSerializer EDTInt64PropertySerializer;
        private static DataContractSerializer TablePropertySerializer;
        private static DataContractSerializer TableFieldPropertySerializer;
        private static DataContractSerializer MenuItemPropertySerializer;
        private static DataContractSerializer MenuPropertySerializer;
        private static DataContractSerializer MenuItemInMenuSerializer;
        private static DataContractSerializer EDTRelationSeriallizer;
        private static DataContractSerializer BaseEnumPropertySerializer;
        private static DataContractSerializer BaseEnumElementPropertySerializer;
        private static DataContractSerializer TableFieldGroupPropertySerializer;
        private static DataContractSerializer TableIndexPropertySerializer;
        private static DataContractSerializer TableFieldGroupFieldPropertySerializer;
        private static DataContractSerializer TableIndexFieldPropertySerializer;
        private static DataContractSerializer TableRelationPropertySerializer;
        private static DataContractSerializer TableRelationFieldPropertySerializer;
        private static DataContractSerializer TableDeleteActionPropertySerializer;
        private static DataContractSerializer TableFieldStringPropertySerializer;
        private static DataContractSerializer TableFieldRealPropertySerializer;
        private static DataContractSerializer TableFieldIntPropertySerializer;
        private static DataContractSerializer TableFieldEnumPropertySerializer;
        private static DataContractSerializer TableFieldDatePropertySerializer;
        private static DataContractSerializer TableFieldTimePropertySerializer;
        private static DataContractSerializer TableFieldContainerPropertySerializer;
        private static DataContractSerializer TableFieldInt64PropertySerializer;
        private static DataContractSerializer MethodPropertySerializer;
        private static DataContractSerializer FormPropertySerializer;
        private static DataContractSerializer FormDesignPropertySerializer;
        private static DataContractSerializer QueryPropertySerializer;
        private static DataContractSerializer QueryDataSourcePropertySerializer;
        private static DataContractSerializer QueryDataSourceFieldsPropertySerializer;
        private static DataContractSerializer QueryDataSourceFieldPropertySerializer;
        private static DataContractSerializer QueryDataSourceSortingFieldPropertySerializer;
        private static DataContractSerializer QueryDataSourceRangePropertySerializer;
        private static DataContractSerializer ButtonPropertySerializer;
        private static DataContractSerializer MenuItemButtonPropertySerializer;
        private static DataContractSerializer ClassPropertySerializer;
        private static DataContractSerializer TabPropertySerializer;
        private static DataContractSerializer TabPagePropertySerializer;
        private static DataContractSerializer GridPropertySerializer;
        private static DataContractSerializer GroupPropertySerializer;
        private static DataContractSerializer TreePropertySerializer;
        private static DataContractSerializer SpiltPropertySerializer;
        private static DataContractSerializer FilterPropertySerializer;
        private static DataContractSerializer PanelPropertySerializer;
        private static DataContractSerializer WebFormSingleSerializer;
        private static DataContractSerializer WebFormMasterSlaveSerializer;
        private static DataContractSerializer WebFormTreeSerializer;
        private static DataContractSerializer WebFormParameterSerializer;
        private static DataContractSerializer WebFormParaByUserSerializer;
        private static DataContractSerializer WebFormRelationSerializer;
        private static DataContractSerializer WebFormBlankSerializer;
        private static DataContractSerializer WebFormFieldGroupSerializer;
        private static DataContractSerializer WebFormButtonSerializer;
        
        private static DataContractSerializer tempSerializer;

        private static BaseProperty ret;

        public static BaseProperty getObject(string nodeType, FileStream fileStream)
        {
            XmlDictionaryReader reader =
                XmlDictionaryReader.CreateTextReader(fileStream, new XmlDictionaryReaderQuotas());
            reader.MoveToStartElement();
            string propertyName = reader.LocalName;

            switch (nodeType)
            {
                case OT.ExtendDataType:
                    {
                        switch (propertyName)
                        {
                            case PropertyTypes.EDTStringProperty:
                                {
                                    if (EDTStringPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTStringProperty));
                                        EDTStringPropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTStringProperty)EDTStringPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.EDTIntProperty:
                                {
                                    if (EDTIntPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTIntProperty));
                                        EDTIntPropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTIntProperty)EDTIntPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.EDTRealProperty:
                                {
                                    if (EDTRealPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTRealProperty));
                                        EDTRealPropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTRealProperty)EDTRealPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.EDTDateProperty:
                                {
                                    if (EDTDatePropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTDateProperty));
                                        EDTDatePropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTDateProperty)EDTDatePropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.EDTTimeProperty:
                                {
                                    if (EDTTimePropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTTimeProperty));
                                        EDTTimePropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTTimeProperty)EDTTimePropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.EDTEnumProperty:
                                {
                                    if (EDTEnumPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTEnumProperty));
                                        EDTEnumPropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTEnumProperty)EDTEnumPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.EDTContainerProperty:
                                {
                                    if (EDTContainerPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTContainerProperty));
                                        EDTContainerPropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTContainerProperty)EDTContainerPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.EDTInt64Property:
                                {
                                    if (EDTInt64PropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTInt64Property));
                                        EDTInt64PropertySerializer = tempSerializer;
                                    }
                                    ret = (EDTInt64Property)EDTInt64PropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            default:
                                {
                                    if (EDTPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(EDTProperty));
                                        EDTPropertySerializer = tempSerializer;
                                    }
                                    /**else
                                        ret = EDTPropertySerializer;**/
                                    ret = (EDTProperty)EDTPropertySerializer.ReadObject(reader, true);
                                    break;
                                }

                            /*if (name =="EDTDateProperty")
        {
            tempSerializer = new DataContractSerializer(typeof(EDTDateProperty));
            EDTDatePropertySerializer = tempSerializer;
            ret = (EDTDateProperty)EDTDatePropertySerializer.ReadObject(reader, true);
                       
        }
                       
        else
        {
        if (EDTPropertySerializer == null)
        {
                           
            tempSerializer = new DataContractSerializer(typeof(EDTProperty));
            EDTPropertySerializer = tempSerializer;
        }
        /**else
            ret = EDTPropertySerializer;**/
                            // ret = (EDTProperty)EDTPropertySerializer.ReadObject(reader, true);
                            //}*/
                        }
                        break;
                    }

                case OT.Table:
                    {
                        if (TablePropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(TableProperty));
                            TablePropertySerializer = tempSerializer;
                        }
                        ret = (TableProperty)TablePropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.TableField:
                    {
                        switch (propertyName)
                        {
                            case PropertyTypes.TableFieldStringProperty:
                                {
                                    if (TableFieldStringPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldStringProperty));
                                        TableFieldStringPropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldStringProperty)
                                        TableFieldStringPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.TableFieldRealProperty:
                                {
                                    if (TableFieldRealPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldRealProperty));
                                        TableFieldRealPropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldRealProperty)
                                        TableFieldRealPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.TableFieldIntProperty:
                                {
                                    if (TableFieldIntPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldIntProperty));
                                        TableFieldIntPropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldIntProperty)TableFieldIntPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.TableFieldDateProperty:
                                {
                                    if (TableFieldDatePropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldDateProperty));
                                        TableFieldDatePropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldDateProperty)
                                        TableFieldDatePropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.TableFieldTimeProperty:
                                {
                                    if (TableFieldTimePropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldTimeProperty));
                                        TableFieldTimePropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldTimeProperty)
                                        TableFieldTimePropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.TableFieldEnumProperty:
                                {
                                    if (TableFieldEnumPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldEnumProperty));
                                        TableFieldEnumPropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldEnumProperty)
                                        TableFieldEnumPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.TableFieldContainerProperty:
                                {
                                    if (TableFieldContainerPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldContainerProperty));
                                        TableFieldContainerPropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldContainerProperty)
                                        TableFieldContainerPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            case PropertyTypes.TableFieldInt64Property:
                                {
                                    if (TableFieldInt64PropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldInt64Property));
                                        TableFieldInt64PropertySerializer = tempSerializer;
                                    }
                                    ret =
                                        (TableFieldInt64Property)
                                        TableFieldInt64PropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                            default:
                                {
                                    if (TableFieldPropertySerializer == null)
                                    {
                                        tempSerializer = new DataContractSerializer(typeof(TableFieldProperty));
                                        TableFieldPropertySerializer = tempSerializer;
                                    }
                                    ret = (TableFieldProperty)TableFieldPropertySerializer.ReadObject(reader, true);
                                    break;
                                }
                        }

                        break;
                    }
                case OT.MenuItem:
                    {
                        if (MenuItemPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(MenuItemProperty));
                            MenuItemPropertySerializer = tempSerializer;
                        }
                        ret = (MenuItemProperty)MenuItemPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Menu:
                    {
                        if (MenuPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(MenuProperty));
                            MenuPropertySerializer = tempSerializer;
                        }
                        ret = (MenuProperty)MenuPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.MenuItemInMenu:
                    {
                        if (MenuItemInMenuSerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(MenuItemInMenuProperty));
                            MenuItemInMenuSerializer = tempSerializer;
                        }
                        ret = (MenuItemInMenuProperty)MenuItemInMenuSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.EDTRelation:
                    {
                        if (EDTRelationSeriallizer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(EDTRelationProperty));
                            EDTRelationSeriallizer = tempSerializer;
                        }
                        ret = (EDTRelationProperty)EDTRelationSeriallizer.ReadObject(reader, true);
                        break;
                    }
                case OT.BaseEnum:
                    {
                        if (BaseEnumPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(BaseEnumProperty));
                            BaseEnumPropertySerializer = tempSerializer;
                        }
                        ret = (BaseEnumProperty)BaseEnumPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.EnumElement:
                    {
                        if (BaseEnumElementPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(BaseEnumElementProperty));
                            BaseEnumElementPropertySerializer = tempSerializer;
                        }
                        ret = (BaseEnumElementProperty)BaseEnumElementPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.FieldGroup:
                    {
                        if (TableFieldGroupPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(TableFieldGroupProperty));
                            TableFieldGroupPropertySerializer = tempSerializer;
                        }
                        ret = (TableFieldGroupProperty)TableFieldGroupPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.GroupField:
                    {
                        if (TableFieldGroupFieldPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(GroupFieldProperty));
                            TableFieldGroupFieldPropertySerializer = tempSerializer;
                        }
                        ret = (GroupFieldProperty)TableFieldGroupFieldPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Index:
                    {
                        if (TableIndexPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(TableIndexProperty));
                            TableIndexPropertySerializer = tempSerializer;
                        }
                        ret = (TableIndexProperty)TableIndexPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.IndexField:
                    {
                        if (TableIndexFieldPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(TableIndexFieldProperty));
                            TableIndexFieldPropertySerializer = tempSerializer;
                        }
                        ret = (TableIndexFieldProperty)TableIndexFieldPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.TableRelation:
                    {
                        if (TableRelationPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(TableRelationProperty));
                            TableRelationPropertySerializer = tempSerializer;
                        }
                        ret = (TableRelationProperty)TableRelationPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.TableRelationField:
                    {
                        if (TableRelationFieldPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(TableRelationFieldProperty));
                            TableRelationFieldPropertySerializer = tempSerializer;
                        }
                        ret = (TableRelationFieldProperty)TableRelationFieldPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.TableDeleteAction:
                    {
                        if (TableDeleteActionPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(TableDeleteActionProperty));
                            TableDeleteActionPropertySerializer = tempSerializer;
                        }
                        ret = (TableDeleteActionProperty)TableDeleteActionPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.TableMethod:
                    {
                        if (MethodPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(MethodProperty));
                            MethodPropertySerializer = tempSerializer;
                        }
                        ret = (MethodProperty)MethodPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Form:
                    {
                        if (FormPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(FormProperty));
                            FormPropertySerializer = tempSerializer;
                        }
                        ret = (FormProperty)FormPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.FormDesign:
                    {
                        if (FormDesignPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(FormDesignProperty));
                            FormDesignPropertySerializer = tempSerializer;
                        }
                        ret = (FormDesignProperty)FormDesignPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Query:
                    {
                        if (QueryPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(QueryProperty));
                            QueryPropertySerializer = tempSerializer;
                        }
                        ret = (QueryProperty)QueryPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.QueryMethod:
                    {
                        if (MethodPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(MethodProperty));
                            MethodPropertySerializer = tempSerializer;
                        }
                        ret = (MethodProperty)MethodPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.QueryDataSource:
                    {
                        if (QueryDataSourcePropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(QueryDataSourceProperty));
                            QueryDataSourcePropertySerializer = tempSerializer;
                        }
                        ret = (QueryDataSourceProperty)QueryDataSourcePropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.QueryDataSourceFields:
                    {
                        if (QueryDataSourceFieldsPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(QueryDataSourceFieldsProperty));
                            QueryDataSourceFieldsPropertySerializer = tempSerializer;
                        }
                        ret =
                            (QueryDataSourceFieldsProperty)
                            QueryDataSourceFieldsPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.QueryDataSourceField:
                    {
                        if (QueryDataSourceFieldPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(QueryDataSourceFieldProperty));
                            QueryDataSourceFieldPropertySerializer = tempSerializer;
                        }
                        ret =
                            (QueryDataSourceFieldProperty)
                            QueryDataSourceFieldPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.QueryDataSourceSorting:
                    {
                        if (QueryDataSourceSortingFieldPropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(QueryDataSourceSortingFieldProperty));
                            QueryDataSourceSortingFieldPropertySerializer = tempSerializer;
                        }
                        ret =
                            (QueryDataSourceSortingFieldProperty)
                            QueryDataSourceSortingFieldPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.QueryDataSourceRange:
                    {
                        if (QueryDataSourceRangePropertySerializer == null)
                        {
                            tempSerializer = new DataContractSerializer(typeof(QueryDataSourceRangProperty));
                            QueryDataSourceRangePropertySerializer = tempSerializer;
                        }
                        ret =
                            (QueryDataSourceRangProperty)
                            QueryDataSourceRangePropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Button:
                    {
                        ButtonPropertySerializer = ButtonPropertySerializer ??
                                                   new DataContractSerializer(typeof(ButtonProperty));
                        ret = (ButtonProperty)ButtonPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.MenuItemButton:
                    {
                        MenuItemButtonPropertySerializer = MenuItemButtonPropertySerializer ??
                                                           new DataContractSerializer(typeof(MenuItemButtonProperty));
                        ret = (MenuItemButtonProperty)MenuItemButtonPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Class:
                    {
                        ClassPropertySerializer = ClassPropertySerializer ??
                                                  new DataContractSerializer(typeof(ClassProperty));
                        ret = (ClassProperty)ClassPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Tab:
                    {
                        TabPropertySerializer = TabPropertySerializer ??
                                                new DataContractSerializer(typeof(TabProperty));
                        ret = (TabProperty)TabPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.TabPage:
                    {
                        TabPagePropertySerializer = TabPagePropertySerializer ??
                                                    new DataContractSerializer(typeof(TabPageProperty));
                        ret = (TabPageProperty)TabPagePropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Grid:
                    {
                        GridPropertySerializer = GridPropertySerializer ??
                                                 new DataContractSerializer(typeof(GridProperty));
                        ret = (GridProperty)GridPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Group:
                    {
                        GroupPropertySerializer = GroupPropertySerializer ??
                                                  new DataContractSerializer(typeof(GroupProperty));
                        ret = (GroupProperty)GroupPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Tree:
                    {
                        TreePropertySerializer = TreePropertySerializer ??
                                                 new DataContractSerializer(typeof(TreeProperty));
                        ret = (TreeProperty)TreePropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Spilt:
                    {
                        SpiltPropertySerializer = SpiltPropertySerializer ??
                                                  new DataContractSerializer(typeof(SplitProperty));
                        ret = (SplitProperty)SpiltPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Filter:
                    {
                        FilterPropertySerializer = FilterPropertySerializer ??
                                                   new DataContractSerializer(typeof(FilterProperty));
                        ret = (FilterProperty)FilterPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.Panel:
                    {
                        PanelPropertySerializer = PanelPropertySerializer ??
                                                  new DataContractSerializer(typeof(PanelProperty));
                        ret = (PanelProperty)PanelPropertySerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormSingle:
                    {
                        WebFormSingleSerializer = WebFormSingleSerializer ?? new DataContractSerializer(typeof(WebFormSingleProperty));
                        ret = (WebFormSingleProperty)WebFormSingleSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormMasterSlave:
                    {
                        WebFormMasterSlaveSerializer = WebFormMasterSlaveSerializer ?? new DataContractSerializer(typeof(WebFormMasterSlaveProperty));
                        ret = (WebFormMasterSlaveProperty)WebFormMasterSlaveSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormTree:
                    {
                        WebFormTreeSerializer = WebFormTreeSerializer ?? new DataContractSerializer(typeof(WebFormTreeProperty));
                        ret = (WebFormTreeProperty)WebFormTreeSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormParameter:
                    {
                        WebFormParameterSerializer = WebFormParameterSerializer ?? new DataContractSerializer(typeof(WebFormParameterProperty));
                        ret = (WebFormParameterProperty)WebFormParameterSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormParaByUser:
                    {
                        WebFormParaByUserSerializer = WebFormParaByUserSerializer ?? new DataContractSerializer(typeof(WebFormParaByUserProperty));
                        ret = (WebFormParaByUserProperty)WebFormParaByUserSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormRelation:
                    {
                        WebFormRelationSerializer = WebFormRelationSerializer ?? new DataContractSerializer(typeof(WebFormRelationProperty));
                        ret = (WebFormRelationProperty)WebFormRelationSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormBlank:
                    {
                        WebFormBlankSerializer = WebFormBlankSerializer ?? new DataContractSerializer(typeof(WebFormBlankProperty));
                        ret = (WebFormBlankProperty)WebFormBlankSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormFieldGroup:
                    {
                        WebFormFieldGroupSerializer = WebFormFieldGroupSerializer ?? new DataContractSerializer(typeof(WebFormFieldGroupProperty));
                        ret = (WebFormFieldGroupProperty)WebFormFieldGroupSerializer.ReadObject(reader, true);
                        break;
                    }
                case OT.WebFormButton:
                    {
                        WebFormButtonSerializer = WebFormButtonSerializer ?? new DataContractSerializer(typeof(WebFormButtonProperty));
                        ret = (WebFormButtonProperty)WebFormButtonSerializer.ReadObject(reader, true);
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
            return ret;
        }
    }
}